package com.ding.oss.controller;

import com.ding.commonutils.Result;
import com.ding.oss.service.Ossservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.FileNotFoundException;

@RestController
@RequestMapping("/eduoss/fileoss")
@CrossOrigin
@EnableDiscoveryClient
public class Osscontroller {

    @Autowired
    private Ossservice ossservice;

    //上传头像的方法
    @PostMapping
    public Result uploadOssFile(MultipartFile file) throws FileNotFoundException {
        //获取上传文件  MultipartFile
        //返回上传到oss的路径
          String url = ossservice.uploadFileAvatar(file);
      return Result.ok().data("url",url);
    }
}
